
#include "stdafx.h"
#include "utils.h"
#include <iostream>


unsigned int hex_char_to_int(char chr)
{
	switch (chr)
	{
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':
		return chr - 87;
	default:
		return chr - '0';
	}
}


std::vector<byte> string_to_vector(std::string data)
{
	if (data.size() % 2 != 0)
	{
		std::cerr << "invalid data when convert string to vector" << std::endl;
		return std::vector<byte>(1, 0);
	}

	std::vector<byte> v;
	for (std::size_t i = 0; i < data.size(); i += 2)
	{
		byte b = hex_char_to_int(data.at(i)) << 4;
		b |= hex_char_to_int(data.at(i + 1));
		v.push_back(b);
	}

	return v;
}


